package cn.dengta.webapp.trade.model;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.webapp.trade.entity.UserLayerConfig;
import cn.dengta.webapp.trade.entity.meta.*;
import cn.dengta.webapp.trade.entity.meta.MetaConfig.MetaRuleConfig;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;
import me.codeplayer.util.JSONUtil;
import me.codeplayer.util.StringUtil;

/**
 * 规则类型枚举
 */
@Getter
public enum MetaConfigType implements ValueProxyImpl<MetaConfigType, Integer> {
	/** 首充礼包 */
	RECHARGE_FIRST_BAGS(0, "首充大礼包", true),
	/** 推荐额外展示 */
	RECOMMEND_GREET_UP(1, "推荐额外展示", RecommendGreetUpRule.class, true, false),
	/** 用户昵称 */
	NICKNAME(2, "昵称", true, true),
	/** 邮箱模板 */
	EMAIL_TEMP(3, "邮箱模板", true),
	/** 手机短信模板 */
	PHONE_TEMP(4, "手机短信模板", true),
	/** 邀请用户规则 */
	INVITE_USER_RULE(5, "邀请用户规则", InviteUserRule.class, true, false),
	/** 个人简介 */
	SLOGAN(6, "个人简介", true, true),
	/** 缘分雷达配置 */
	FATE_RADAR(7, "缘分雷达配置", FateRadarRule.class, true, false),
	/** 速配配置 */
	SPEED_DATING(8, "速配音视频配置", SpeedDatingRule.class, true, false),
	/** 主播补贴规则 */
	ANCHOR_ASSESS(9, "主播补贴规则", AnchorAssessRule.class, true, false),
	/** 速配奖励规则 */
	SPEED_DATING_REWARD(10, "速配奖励规则", SpeedDatingRewardRule.class, true, false),
	/** 充值全额返规则 */
	DOUBLE_GIVE_RECHARGE(11, "充值全额返规则", DoubleGiveRechargeRule.class, true, false),
	/** 星球探险 */
	PLANET_EXPLORE(12, "星球探险配置", PlanetExploreRule.class, true, false),
	/** 甜蜜pick */
	SWEET_PICK(13, "甜蜜pick配置", SweetPickRule.class, true, false),
	/** 男用户分层 */
	MAN_LAYER(14, "男用户分层配置", UserLayerConfig.class, true, false),
	/** 女用户分层 */
	WOMAN_LAYER(15, "女用户分层配置", UserLayerConfig.class, true, false),
	/** 聊天回复收益配置 */
	CHAT_REPLY_EARN(16, "聊天回复收益配置", ChatReplyEarnRule.class, true, false),
	/** 牵线配置 */
	PULL_WIRES(17, "牵线配置", PullWiresRuleV1.class, true, true),
	/** 互关免费聊天 */
	IM_FREE_CHAT(18, "互关免费聊天", ImFreeChatRule.class, true, false),
	/** 直播主播评级配置 */
	LIVE_ANCHOR_ASSESS(19, "直播主播评级配置", LiveAnchorAssessRule.class, true, false),
	/** 1v1音视频通话配置 */
	MEDIA(20, "1v1音视频通话配置", MediaRule.class, true, false),
	/** 欺诈词库配置 */
	FRAUD(21, "欺诈词库配置", FraudRule.class, true, false),
	/** 中文个人简介，国内版 */
	SLOGAN_CN(22, "个人简介", true, true),
	/** 国内首充礼包 配置 */
	INTER_FIRST_PAY_BAG(23, "国内首充礼包", FirstPayInterBag.class, false, false),
	/** 用户充值限制配置 */
	USER_RECHARGE_LIMIT(24, "用户每日充值限制配置", UserRechargeLimitConfig.class, true, true),
	//
	;

	@EnumValue
	public Integer value;
	/** 是否显示 */
	public boolean visible;
	/** 同类型同语言可重复存在 */
	public boolean repeatable;
	public final Class<? extends MetaRuleConfig> configClazz;
	final ValueProxy<MetaConfigType, Integer> proxy;
	//

	MetaConfigType(Integer value, String label, Class<? extends MetaRuleConfig> configClazz, boolean visible, boolean repeatable) {
		this.value = value;
		this.visible = visible;
		this.repeatable = repeatable;
		this.configClazz = configClazz;
		this.proxy = new ValueProxy<>(this, ordinal(), label);
	}

	MetaConfigType(Integer value, String label, boolean visible, boolean repeatable) {
		this(value, label, null, visible, repeatable);
	}

	MetaConfigType(Integer value, String label, boolean visible) {
		this(value, label, null, visible, false);
	}

	public String serialize(MetaRuleConfig config) {
		return config == null ? "" : JSONUtil.serialize(config);
	}

	public MetaRuleConfig deserialize(String configJSONStr) {
		return StringUtil.isEmpty(configJSONStr) ? null : JSONUtil.parseObject(configJSONStr, configClazz);
	}

	@Override
	public ValueProxy<MetaConfigType, Integer> getProxy() {
		return proxy;
	}

	public static MetaConfigType[] getValues() {
		return ValueProxy.getCachedArray(MetaConfigType.class, MetaConfigType::values);
	}

	public static MetaConfigType of(Integer value) {
		return NICKNAME.getValueOf(value);
	}
}
